package stack;

import java.util.Stack;

public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;
    /** initialize your data structure here. */
    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if(minStack.empty()){
            minStack.push(x);
        }else{
            if(stack.peek() <= minStack.peek()){
                minStack.push(x);
            }
        }
    }

    public void pop() {
        if(stack.empty()){
            return;
        }else{
            System.out.println("普通栈："+stack.peek());
            System.out.println("最小栈："+minStack.peek());
            if(stack.peek().compareTo(minStack.peek()) == 0){
                minStack.pop();
            }
            stack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }

    public static void main(String[] args) {

        MinStack st = new MinStack();
        st.push(512);
        st.push(-1024);
        st.push(-1024);
        st.push(512);
        st.pop();
        st.pop();
        st.pop();

    }
}